package com.cinyi.ormlite.core;

import java.util.List;
import java.util.Map;
/**
 * 定义连接处理dao接口<br>
 * @author penghui
 *
 * @param <T>
 */
public interface IGenericDao<T> {
	/**
	 * 存储
	 * @param t T
	 * @throws Exception tag
	 */
	void save(T t) throws Exception;
	
	/**
	 * 存储或更新
	 * @param t T
	 * @throws Exception e
	 */
	void saveOrUpdate(T t) throws Exception;
	
	/**
	 * 删除记录
	 * @param id Object
	 * @param clazz Class
	 * @throws Exception e
	 */
	Integer delete(Object id,Class<T> clazz) throws Exception;
	
	/**
	 * 更改记录
	 * @param t T
	 * @throws Exception e
	 */
	Integer update(T t) throws Exception;
	 
	/**
	 * 更改数据，是否忽略空值数据
	 * @param t T
	 * @param ignoreNull 
	 * @throws Exception e
	 */
	Integer update(T t,boolean ignoreNull) throws Exception;
	
	/**
	 * as same as findOne
	 * 
	 * @param id Object
	 * @param clazz T
	 * @return T
	 * @throws Exception e
	 * @deprecated
	 */
	T get(Object id,Class<T> clazz) throws Exception;
	
	/**
	 * 
	 * @param id Object
     * @param clazz T
     * @return T
     * @throws Exception e
     */
	T findOne(Object id,Class<T> clazz) throws Exception;
	
	/**
	 * 根据条件查询
	 * @param sqlWhereMap key：条件字段名 value：条件字段值
	 * @param clazz Clazz
	 * @return List<T> 
	 * @throws Exception e
	 */
	List<T> find(Class<T> clazz , Map<String,Object> sqlWhereMap,String orderby) throws Exception;
	
	/**
	 * 根据对象值查询数据库
	 * @param bean
	 * @return
	 * @throws Exception
	 */
	List<T> find(T bean) throws Exception;
	
	/**
	 * 
	 * @param clazz
	 * @param sql
	 * @return
	 * @throws Exception
	 */
	List<T> findBySQL(Class<T> clazz , String sql) throws Exception;
	
	/**
	 * 根据sQL查询对象
	 * @param sQL
	 * @param clazz
	 * @return
	 * @throws Exception
	 */
	List<T> findBySQL(Class<T> clazz , String sQL,List<Object> params) throws Exception;
	
	/**
	 * 分页查询
	 * @param sqlWhereMap
	 * @param clazz
	 * @return
	 */
	List<T> findBySQL(Class<T> clazz , String sql,List<Object> params,int start,int pageSize) throws Exception;
	
	/**
	 * 计算总数
	 * @param sql
	 * @return
	 * @throws SQLException 
	 * @throws Exception 
	 */
	Long count(Map<String,Object> sqlWhereMap , Class<T> clazz ) throws Exception;
	
	/**
	 * 对象参数<br>
	 * @param t
	 * @return
	 * @throws Exception
	 */
	Long count(T t) throws Exception;
	
	/**
	 * 通过sql计算总数
	 * @param sql
	 * @return
	 * @throws Exception
	 */
	Long count(String sql) throws Exception;
	
	/**
	 * 参数计算总数
	 * @param sql
	 * @param params
	 * @return
	 * @throws Exception
	 */
	Long count(String sql, List<Object> params) throws Exception;
	
	Integer executeSQL(String sql, List<Object> params) throws Exception;
	
	void close();
	
}
